﻿var is_ie = document.all ? true : false;
var is_ff = window.addEventListener ? true : false;

function refreshmainframe(e) {
    e = e ? e : window.event;
    actualCode = e.keyCode ? e.keyCode : e.charCode;
    if (actualCode == 116 && parent.right) {
        parent.right.location.reload();
        if (is_ie) {
            e.keyCode = 0;
            e.returnValue = false;
        }
        else {
            e.preventDefault();
        }
    }
}

function showhelp(o, obj) {
    if (document.getElementById("div" + obj.alt)) {
        closeDiv(document.getElementById("div" + obj.alt));
    }
    else {
        var div = document.createElement("div");
        div.style.top = (o.bottom) + "px";
        div.style.left = (o.left) + "px";
        div.id = "div" + obj.alt;
        div.className = "helpInfo"; //层样式
        document.body.appendChild(div);
        div.innerHTML = obj.alt;
    }
}

function helpInf(obj) {
    showhelp(getInfo(obj), obj);
}
var getInfo = function (o) {//取得坐标
    var to = new Object();
    to.left = to.right = to.top = to.bottom = 0;
    var twidth = o.offsetWidth;
    var theight = o.offsetHeight;
    while (o != document.body) {
        to.left += o.offsetLeft;
        to.top += o.offsetTop + 1;
        o = o.offsetParent;
    }
    to.right = to.left + twidth;
    to.bottom = to.top + theight;
    return to;
}
var closeDiv = function (obj) { //删除层
    obj.parentNode.removeChild(obj);
}
/*
//显示错误信息
function ErrInf(obj,errMsg){
if(document.getElementById("ErrMsg"))//+obj.name
{
closeDiv(document.getElementById("ErrMsg"));
}
var div = document.createElement("span");
div.id = "ErrMsg"//+obj.name;
div.className = "errInfo";//层样式
insertAfter(div,obj)
div.innerHTML= errMsg;
obj.focus();
} 


function insertAfter(newElement, targetElement) 
{ 
var parent = targetElement.parentNode; 
if(parent.lastChild == targetElement)  
{ 
parent.appendChild(newElement); 
}  
else 
{ 
parent.insertBefore(newElement, targetElement.nextSibling); 
} 
}*/
//更新 2009-12-30
function ErrInf(obj, errMsg) {
    if (document.getElementById("ErrMsg"))//+obj.name
    {
        closeDiv(document.getElementById("ErrMsg"));
    }
    o = getInfo(obj);
    var div = document.createElement("div");
    div.style.top = (o.bottom - obj.clientHeight - 25) + "px";
    div.style.left = (o.left) + "px";
    div.id = "ErrMsg";
    div.className = "errInfo"; //层样式
    document.body.appendChild(div);
    div.innerHTML = errMsg + "<span id=\"spanClose\"><b  style=\"color:red;cursor:pointer;\">x</b></span>";
    $$("spanClose").onclick = function () {
        closeDiv(div);
    }
    obj.focus();
}

































var $$ = function (elementID) { return document.getElementById(elementID) }
var $e = function (obj) { return obj.getElementsByTagName("input") }
function showchildnode(pId) {
    var id = pId.replace("s", "");
    if ($$("c" + id).style.display == "none") {
        $$("c" + id).style.display = "block";
        $$("t" + id).style.background = "#99CCFF";
    }
    else {
        $$("c" + id).style.display = "none";
        $$("t" + id).style.background = "#CCCCCC";
    }
}
function selAll(PId) {
    var pobj = $$(PId);
    var Es = $$("c" + PId).getElementsByTagName("input");
    for (var i = 0; i < Es.length; i++) {
        if (pobj.checked) {
            $$("c" + PId).style.display = "block";
            $$("t" + PId).style.background = "#99CCFF";
            //$$("p"+PId).style.border="5px solid #009900";
            Es[i].checked = true;
        }
        else {
            $$("p" + PId).style.border = "5px solid #FFFCCC";
            Es[i].checked = false;
        }
    }
}
function conclick(ID, pID) {
    if ($$("C" + ID))//判断是否有子结点
    {
        var Es = $e($$("C" + ID));
        for (var i = 0; i < Es.length; i++) {
            Es[i].checked = $$(ID).checked
        }
    }
    /*处理父结点*/
    var flag = false, flag2 = false;
    var pEs = $e($$("C" + pID));
    for (var i = 0; i < pEs.length; i++) {
        if (pEs[i].checked) {
            flag = true;
            break;
        }
    }
    for (var i = 0; i < pEs.length; i++) {
        if (pEs[i].checked == true) {
            flag2 = true;
            break;
        }
    }
    if (!flag) {
        $$(pID).checked = false
        var xsID1 = $$(pID).parentNode.parentNode.id
        var xs1 = xsID1.replace("c", "");
        $$(xs1).checked = false;
    }
    if (flag2) {
        $$(pID).checked = true;
        var xsID1 = $$(pID).parentNode.parentNode.id
        var xs1 = xsID1.replace("c", "");
        $$(xs1).checked = true;
    }
}
/*function GetPID(xsID)
{
if($$(pID).parentNode.parentNode.id!="")
{
return eval parentNode.parentNode
}
}*/
/*
function conclick(cId)
{
var PId =$$(cId).parentNode.parentNode.id;
var id= PId.replace("c","");
var flag=false;
var flag1 =true;
var Es =$$("c"+id).getElementsByTagName("input");
for(var i=0;i<Es.length;i++)
{
if(Es[i].checked==false)
{
flag=true;
break;
}
}
for(var i=0;i<Es.length;i++)
{
if(Es[i].checked==true)
{
flag1=false;
break;
}
}
if(flag)
{
if(flag1)
{
$$("p"+id).style.border="5px solid #FFFCCC"
}
else
{
$$("p"+id).style.border="5px solid lime"
}
$$(id).checked=false;
}
else
{
$$("p"+id).style.border="5px solid #009900"
$$(id).checked=true;
}

}
*/
function ChangeRoleFlag(RoleIDs, userID) {
    $.ajax({
        type: "POST",
        async: false,
        url: "AdminItem.aspx",
        data: "act=CSRF&userID=" + userID + "&ids=" + RoleIDs,
        success: function (msg) {
            $$("sitesDiv").innerHTML = msg;
        }
    });
}

function getRoleChk(userID) {
    var RoleIDs = "";
    var obj = $e($$("chkdiv"));
    for (var i = 0; i < obj.length; i++) {
        if (obj[i].checked) {
            if (RoleIDs == "") {
                RoleIDs += obj[i].value;
            }
            else {
                RoleIDs = RoleIDs + "," + obj[i].value;
            }
        }
    }
    ChangeRoleFlag(RoleIDs, userID);
}

/********  站点列表   **********/
function showsite(o, list) {
    if (document.getElementById("divsite")) {
        closeDiv(document.getElementById("divsite"));
    }
    /*else
    {*/
    var div = document.createElement("div");
    div.style.top = (o.bottom) + "px";
    div.style.left = (o.left) + "px";
    div.id = "divsite";
    div.className = "divsite"; //层样式
    document.body.appendChild(div);
    div.innerHTML = list;
    /*}*/
}
function showsitelist(obj, userID) {
    $.ajax({
        type: "POST",
        async: false,
        url: "AdminItem.aspx",
        data: "act=showsite&id=" + userID,
        success: function (msg) {
            showsite(getInfo1(obj), msg);
        }
    });
}

function showadditionalrightslist(obj, userID) {
    $.ajax({
        type: "POST",
        async: false,
        url: "AdminItem.aspx",
        data: "act=showadditionalrights&id=" + userID,
        success: function (msg) {
            showsite(getInfo1(obj), msg);
        }
    });
}


var getInfo1 = function (o) {//取得坐标
    var to = new Object();
    to.left = to.right = to.top = to.bottom = 0;
    var twidth = o.offsetWidth;
    var theight = o.offsetHeight;
    while (o != document.body) {
        to.left += o.offsetLeft - 28;
        to.top += o.offsetTop - 4;
        o = o.offsetParent;
    }
    to.right = to.left + twidth;
    to.bottom = to.top + theight;
    return to;
}

function showsitelistbyRoleID(obj, roleID) {
    $.ajax({
        type: "POST",
        async: false,
        url: "RoleItem.aspx",
        data: "act=showsite&id=" + roleID,
        success: function (msg) {
            showsite(getInfo1(obj), msg);
        }
    });
}

function changeFlagType(obj) {
    $.ajax({
        type: "POST",
        async: false,
        url: "FlagItem.aspx",
        data: "act=select&ft=" + obj.value,
        success: function (msg) {
            $$("SelParentID").innerHTML = msg;
        }
    });
}

/*----添加采集解析----*/
//显示添加层
function showAddCatchParse(parseType, obj) {
    $$("NodeID").style.display = "none";
    $$("ParseType").selectedIndex = parseType;
    showAddCatchParse1(getInfo(obj));
}
function showAddCatchParse1(o) {
    if ($$("addnewdiv").style.display == "none") {
        $$("addnewdiv").style.display = "block";
    }
    //var div = $$("addnewdiv");
    //div.style.top = (o.bottom-260)+"px";
    //div.style.left = (o.left-230)+"px";
}
//添加保存
function AddCatchParse() {
    if ($$("ParseName").value == "") {
        alert("请填写名称");
        $$("ParseName").focus();
        return false;
    }
    if ($$("ParseBegin").value == "") {
        alert("请填写定位开头");
        $$("ParseBegin").focus();
        return false;
    }
    if ($$("ParseEnd").value == "") {
        alert("请填写定位结尾");
        $$("ParseEnd").focus();
        return false;
    }
    if ($$("ParseTags").value == "") {
        alert("请填写格式化XHTML标签");
        $$("ParseTags").focus();
        return false;
    }
    if ($$("ParseAttributes").value == "") {
        alert("请填写格式化XHTML属性");
        $$("ParseAttributes").focus();
        return false;
    }
    if ($$("ParseRule").value == "") {
        alert("请填写规则");
        $$("ParseRule").focus();
        return false;
    }

    $.ajax({
        type: "POST",
        async: false,
        url: "CatchItem.aspx",
        data: "act=addcatchparse&ParseType=" + $$("ParseType").selectedIndex + "&ParseName=" + $$("ParseName").value + "&ParseBegin=" + $$("ParseBegin").value + "&ParseEnd=" + $$("ParseEnd").value + "&ParseTags=" + $$("ParseTags").value + "&ParseAttributes=" + $$("ParseAttributes").value + "&ParseRule=" + $$("ParseRule").value,
        success: function (msg) {
            if ($$("ParseType").selectedIndex == 0) {
                $$("ListParseID").innerHTML = msg;
            }
            else {
                $$("TextParseID").innerHTML = msg;
            }
            $$("addnewdiv").style.display = "none";
        }
    });
}

function GetAdInfo(obj) {
    $.ajax({
        type: "POST",
        async: false,
        url: "SellerAdItem.aspx",
        data: "act=adbuynumandunit&AdID=" + obj.value,
        success: function (msg) {
            msg = msg.split('|');
            $$("chrUnit").innerHTML = msg[1];
            if (msg[0] == 1)//1文章 
            {
                $$("wordAD").style.display = "block";
                $$("imgAD").style.display = "none";
            }
            else//2图片 3Flash
            {
                $$("wordAD").style.display = "none";
                $$("imgAD").style.display = "block";
                if (msg[0] == 2) {
                    $$("uploadType").innerHTML = "请上传Image";
                }
                else {
                    $$("uploadType").innerHTML = "请上传Flash";
                }
            }
        }
    });
}




/*
Title:分类信息-城市联动
Author:杨雷
Date:2010-03-16
*/
function GetCityInfos(obj) {
    $.ajax({
        type: "POST",
        async: false,
        url: "IndiInfo.aspx",
        data: "act=changcity&province=" + obj.value,
        success: function (msg) {
            $$("spanCity").innerHTML = msg;
            GetAreaInfos(obj, obj.value);
        }
    });
}
function GetAreaInfos(obj, province) {
    $.ajax({
        type: "POST",
        async: false,
        url: "IndiInfo.aspx",
        data: "act=changarea&city=" + obj.value + "&province=" + province,
        success: function (msg) {
            $$("spanArea").innerHTML = msg;
        }
    });
}








//吴菁
//城市Select联动---------------------------------------
function GetCityInfo(obj) {
    $.ajax({
        type: "POST",
        async: false,
        url: "Item.aspx",
        data: "act=changcity&province=" + obj.value,
        success: function (msg) {
            $$("spanCity").innerHTML = msg;
            GetAreaInfo(obj, obj.value);
            //           alert(msg)
        }
    });
}

function GetAreaInfo(obj, province) {
    $.ajax({
        type: "POST",
        async: false,
        url: "Item.aspx",
        data: "act=changarea&city=" + obj.value + "&province=" + province,
        success: function (msg) {
            $$("spanArea").innerHTML = msg;
            //           alert(msg)
        }
    });
}

function GetModuleIDs(obj) {
    $.ajax({
        type: "POST",
        async: false,
        url: "Item.aspx",
        data: "act=changmoduleids&appid=" + obj.value,
        success: function (msg) {
            $$("spanModuleIDs").innerHTML = msg;
            //           alert(msg)
        }
    });
}

function GetTypeID(obj) {
    $.ajax({
        type: "POST",
        async: false,
        url: "Item.aspx",
        data: "act=changtypeid&appid=" + obj.value,
        success: function (msg) {
            $$("spanType").innerHTML = msg;
            //           alert(msg)
        }
    });
}

function GetTypeIDApplyList(obj) {
    $.ajax({
        type: "POST",
        async: false,
        url: "ApplyList.aspx",
        data: "act=changtypeid&appid=" + obj.value,
        success: function (msg) {
            $$("spanType").innerHTML = msg;
            //           alert(msg)
        }
    });
}
//------------------------------------------------------------------------


//添加页面
function RegAddPage(ParseID) {
    $$("RegDiv").style.display = "";
    $$("RegDiv").innerHTML = "loadding……";
    $.ajax({
        type: "POST",
        async: false,
        url: "CatchParseItem.aspx",
        data: "act=regadd&ParseID=" + ParseID,
        success: function (msg) {
            $$("RegDiv").innerHTML = msg;
        }
    });
}

//添加保存
function RegAddSave(ParseID) {
    $$("BoundData").innerHTML = "loadding……";
    $.ajax({
        type: "POST",
        async: false,
        url: "CatchParseItem.aspx",
        data: "act=regaddsave&FieldName=" + $$("FieldName").value + "&Pattern=" + $$("Pattern").value + "&Replacement=" + $$("Replacement").value + "&ParseID=" + $$("ParseID").value,
        success: function (msg) {
            $$("RegDiv").style.display = "none";
            $$("BoundData").innerHTML = msg;
        }
    });
}
//修改页面
function RegEditPage(ParseID) {
    $$("RegDiv").style.display = "";
    $$("RegDiv").innerHTML = "loadding……";
    $.ajax({
        type: "POST",
        async: false,
        url: "CatchParseItem.aspx",
        data: "act=regedit&ID=" + ParseID,
        success: function (msg) {
            $$("RegDiv").innerHTML = msg;
        }
    });
}
//修改保存
function RegEditSave(ID) {
    $$("BoundData").innerHTML = "loadding……";
    $.ajax({
        type: "POST",
        async: false,
        url: "CatchParseItem.aspx",
        data: "act=regeditsave&FieldName=" + $$("FieldName").value + "&Pattern=" + $$("Pattern").value + "&Replacement=" + $$("Replacement").value + "&ID=" + ID,
        success: function (msg) {
            $$("RegDiv").style.display = "none";
            $$("BoundData").innerHTML = msg;
        }
    });
}

//删除
function RegDel(ID) {
    $$("BoundData").innerHTML = "loadding……";
    $.ajax({
        type: "POST",
        async: false,
        url: "CatchParseItem.aspx",
        data: "act=RegDel&ID=" + ID,
        success: function (msg) {
            $$("BoundData").innerHTML = msg;
        }
    });
}

//单页采集新增,杭永昌
//添加页面
function RegContentAddPage(ParseID) {
    $$("RegDiv").style.display = "";
    $$("RegDiv").innerHTML = "loadding……";
    $.ajax({
        type: "POST",
        async: false,
        url: "CatchSingleParseItem.aspx",
        data: "act=regadd&pcid=" + ParseID,
        success: function (msg) {
            $$("RegDiv").innerHTML = msg;
        }
    });
}

//添加保存
function RegContentAddSave(ParseID) {
    $$("BoundData").innerHTML = "loadding……";
    $.ajax({
        type: "POST",
        async: false,
        url: "CatchSingleParseItem.aspx",
        data: "act=regaddsave&FieldName=" + $$("FieldName").value + "&Pattern=" + $$("Pattern").value + "&Replacement=" + $$("Replacement").value + "&pcid=" + $$("pcid").value,
        success: function (msg) {
            $$("RegDiv").style.display = "none";
            $$("BoundData").innerHTML = msg;
        }
    });
}
//修改页面
function RegContentEditPage(ID) {
    $$("RegDiv").style.display = "";
    $$("RegDiv").innerHTML = "loadding……";
    $.ajax({
        type: "POST",
        async: false,
        url: "CatchSingleParseItem.aspx",
        data: "act=regedit&ID=" + ID,
        success: function (msg) {
            $$("RegDiv").innerHTML = msg;
        }
    });
}
//修改保存
function RegContentEditSave(ID) {
    $$("BoundData").innerHTML = "loadding……";
    $.ajax({
        type: "POST",
        async: false,
        url: "CatchSingleParseItem.aspx",
        data: "act=regeditsave&FieldName=" + $$("FieldName").value + "&Pattern=" + $$("Pattern").value + "&Replacement=" + $$("Replacement").value + "&ID=" + ID,
        success: function (msg) {
            $$("RegDiv").style.display = "none";
            $$("BoundData").innerHTML = msg;
        }
    });
}

//删除
function RegContentDel(ID) {
    $$("BoundData").innerHTML = "loadding……";
    $.ajax({
        type: "POST",
        async: false,
        url: "CatchSingleParseItem.aspx",
        data: "act=regDel&ID=" + ID,
        success: function (msg) {
            $$("BoundData").innerHTML = msg;
        }
    });
}


//内容管理 - 置顶

function Content_Top(contentid) {
    $.ajax({
        type: "POST",
        async: false,
        url: "AjaxRequest.aspx",
        data: "act=content_top&contentid=" + contentid,
        success: function (msg) {
            $("#istop" + contentid).text(msg);
        }
    });
}

function Content_Recommend(contentid) {
    $.ajax({
        type: "POST",
        async: false,
        url: "AjaxRequest.aspx",
        data: "act=content_recommend&contentid=" + contentid,
        success: function (msg) {
            $("#isrecommend" + contentid).text(msg);
        }
    });
}

function Content_Hot(contentid) {
    $.ajax({
        type: "POST",
        async: false,
        url: "AjaxRequest.aspx",
        data: "act=content_hot&contentid=" + contentid,
        success: function (msg) {
            $("#ishot" + contentid).text(msg);
        }
    });
}

function Content_Marked(contentid) {
    $.ajax({
        type: "POST",
        async: false,
        url: "AjaxRequest.aspx",
        data: "act=content_marked&contentid=" + contentid,
        success: function (msg) {
            $("#ismarked" + contentid).text(msg);
        }
    });
}

//标签模块获取字段
function GetFields(tableid) {
    $.ajax({
        type: "POST",
        async: false,
        url: "AjaxRequest.aspx",
        data: "act=gettalefields&tableid=" + tableid,
        success: function (msg) {
            $("#fieldsoption").html(msg);
        }
    });
}

//标签模块获取字段
function GenerTagCode(act, id, name, tableid, top, where, order, direction) {
    $.ajax({
        type: "POST",
        async: false,
        url: "AjaxRequest.aspx",
        data: "act=genertagcode&do=" + act + "&id=" + id + "&name=" + name + "&tableid=" + tableid + "&top=" + top + "&where=" + where + "&order=" + order + "&direction=" + direction,
        success: function (msg) {
            $("#setp_1").hide();
            $("#setp_2").show();
            $("#txtcode").text(msg);
        }
    });
}

function SetKeyWords(title) {
    $.ajax({
        type: "POST",
        async: false,
        url: "AjaxRequest.aspx",
        data: "act=getkeywords&title=" + title,
        success: function (msg) {
            $("#txtkeywords").val(msg);
        }
    });
}




